﻿namespace PrismEx.SampleApp.Modules.ShowDialog
{
    using System;
    using System.ComponentModel.Composition;

    using Microsoft.Practices.Prism.Commands;
    using Microsoft.Practices.Prism.Events;
    using Microsoft.Practices.Prism.MefExtensions.Modularity;
    using Microsoft.Practices.Prism.Modularity;
    using Microsoft.Practices.ServiceLocation;

    using PrismEx.Events;
    using PrismEx.Events.Navigation;

    [ModuleExport(typeof(ShowDialogModule))]
    public class ShowDialogModule : IModule
    {
        private readonly IEventAggregator eventAggregator;

        private readonly IServiceProvider serviceLocator;

        [ImportingConstructor]
        public ShowDialogModule(IEventAggregator eventAggregator, IServiceLocator serviceLocator)
        {
            this.eventAggregator = eventAggregator;
            this.serviceLocator = serviceLocator;
        }

        public void Initialize()
        {
            this.eventAggregator.Publish(
                new InjectInstanceIntoRegionEvent
                    {
                        RegionName = "NavigationRegion",
                        Instance = new
                        {
                            Text = "Show Dialog",
                            Command = new DelegateCommand<object>(a => this.eventAggregator.Publish(new ShowDialogEvent() { Uri = new Uri(typeof(MyDialogView).FullName, UriKind.Relative) }))
                        }
                    });
        }      
    }
}
